//
//  ContactTableViewCell.m
//  HuaRun2
//
//  Created by admin on 17/8/29.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "ContactTableViewCell.h"
#import "ContactPersonModel.h"
#import "Meeting_Detail_OutPerson.h"

@interface ContactTableViewCell ()
@property (nonatomic, strong) UIView * backView;

//名字
@property (nonatomic, strong) UILabel * nameLab;
//中文名字
@property (nonatomic, strong) UILabel * nameLabChi;
//公司
@property (nonatomic, strong) UILabel * companyLab;
//电话
@property (nonatomic, strong) UIButton * phoneBtn;
//email
@property (nonatomic, strong) UIButton * emailBtn;

@end

@implementation ContactTableViewCell

#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = RGBA(249, 249, 249, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {

    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.nameLabChi];
    [self.contentView addSubview:self.companyLab];

    [self.contentView addSubview:self.phoneBtn];
    [self.contentView addSubview:self.emailBtn];

//    _nameLab.text = @"英文名";
//    _nameLabChi.text = @"英文名";
    
//    _companyLab.text = [NSString stringWithFormat:@"%@%@", kTestStr, kTestStr];
    
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView);
    }];

    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.phoneBtn.mas_left).offset(-kMargin10);
        make.height.mas_equalTo(20);
    }];
    
    [self.nameLabChi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(ws.nameLab);
        make.top.mas_equalTo(ws.nameLab.mas_bottom);
    }];
    
    [self.companyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.nameLab);
        make.top.mas_equalTo(ws.nameLabChi.mas_bottom).offset(kMargin10);
        make.right.mas_equalTo(ws.nameLab);
    }];
    
    [self.phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.nameLab);
        make.right.mas_equalTo(ws.emailBtn.mas_left).offset(-kMargin10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];

    [self.emailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.nameLab);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
        make.size.mas_equalTo(ws.phoneBtn);
    }];

}
#pragma mark - setter getter 
- (void)setContactPersonModel:(ContactPersonModel *)contactPersonModel {
    _contactPersonModel = contactPersonModel;

//    中文名是：nameChinese英文名是  lastName + firstName
//     title department accountName
    _nameLab.text =  [NSString stringWithFormat:@"%@ %@",
                     [NSString showSpaceStringWithStr: contactPersonModel.lastName],
                     [NSString showSpaceStringWithStr: contactPersonModel.firstName]];
    _nameLabChi.text = [NSString showSpaceStringWithStr: contactPersonModel.nameChinese ];
#pragma mark 测试
    _companyLab.text =  [NSString stringWithFormat:@"%@\n%@\n%@",
                        [NSString showSpaceStringWithStr: contactPersonModel.title],
                        [NSString showSpaceStringWithStr: contactPersonModel.department],
                        [NSString showSpaceStringWithStr: contactPersonModel.department]];

}

- (void)setMeeting_Detail_OutPerson:(Meeting_Detail_OutPerson *)meeting_Detail_OutPerson {
    _meeting_Detail_OutPerson = meeting_Detail_OutPerson;
    _nameLab.text = [NSString showSpaceStringWithStr:meeting_Detail_OutPerson.name];
    _companyLab.text = [NSString showSpaceStringWithStr:meeting_Detail_OutPerson.companyName];
    
}

//companyName: "1",   --公司名称
//departmentName: "1",   -- 部门
//id: "1",   --id
//meetingId: "1",   --会议id
//name: "",    --姓名
//positionName: "1"   -- 职位
- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLab.numberOfLines = 1;
    }
    return _nameLab;
}

- (UILabel *)nameLabChi {
    if (!_nameLabChi) {
        self.nameLabChi = [UILabel new];
        _nameLabChi.textAlignment = NSTextAlignmentLeft;
        _nameLabChi.font = kGeneralFontSize;
        _nameLabChi.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLabChi.numberOfLines = 1;
    }
    return _nameLabChi;
}

- (UILabel *)companyLab {
    if (!_companyLab) {
        self.companyLab = [UILabel new];
        _companyLab.textAlignment = NSTextAlignmentLeft;
        _companyLab.font = kGeneralFontSize;
        _companyLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _companyLab.numberOfLines = 3;
    }
    return _companyLab;
}

- (UIView *)backView {
    if (!_backView) {
        self.backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UIButton *)phoneBtn {
    if (!_phoneBtn) {
        self.phoneBtn = [UIButton new];
        [_phoneBtn setBackgroundImage:[UIImage imageNamed:@"icon_phone"]
                             forState:(UIControlStateNormal)];
    }
    return _phoneBtn;
}

- (UIButton *)emailBtn {
    if (!_emailBtn) {
        self.emailBtn = [UIButton new];
        [_emailBtn setBackgroundImage:[UIImage imageNamed:@"icon_email"]
                             forState:(UIControlStateNormal)];
    }
    return _emailBtn;
}

@end
